
function love.load()
    Object = require"classic"
    require"button";
    x1_press = 150;
    y1_press = 150;
    function_x = x1_press+5;
    function_y = y1_press +5;
    exit_x = x1_press;
    exit_y = y1_press +80;
    Button_function = button("function",5,5,x1_press,y1_press,75,30);
    Button_exist = button("Exit",20,5,exit_x,exit_y,75,30);
   
    --弹窗页面
    page_x = 150;
    page_y =50;
    width =400;
    height = 300;
    speed = 0.5;
    button_speed1 = button("speed up to 1",10,5,page_x+40,page_y+100,140,30)
    button_speed2 = button("speed back",17,5,page_x+210,page_y+100,140,30)
    button_exit = button("return",15,5,page_x+155,page_y+200,75,30)
    button_exit1 = button("exit",20,5,2*page_x+60,2*page_y+20,75,30)
    button_return = button("return",10,5,2*page_x+60,2*page_y+60,75,30)
    button_reset  = button("reset",10,5,2*page_x+60,2*page_y+100,75,30)
    function draw_page()
     if Button_function:isClick() then
       love.graphics.setColor(0.01,0.02,0.03)
       love.graphics.rectangle("fill",page_x,page_y,width,height);
       button_speed1:draw_button(0.1,0.3,0.4);
       button_speed2:draw_button(0.2,0.3,0.4);
        button_exit:draw_button(0.3,0.3,0.4);
        elseif Button_exist:isClick() then
        love.graphics.setColor(0.01,0.02,0.03)
         love.graphics.rectangle("fill",2*page_x,2*page_y,width/2,height/2);
            button_exit1:draw_button(0.1,0.3,0.4);
          button_return:draw_button(0.2,0.3,0.4);
          button_reset:draw_button(0.3,0.3,0.4);
     end        

   end

    myBackground = love.graphics.newImage("backgroud.png");
--画球
     x = 377;
     y = 107;
     z = 7;
     color1 = 0.4;
     color2 = 0.4;
     color3 = 0.5;
     alpha = 1
    function draw_ball(x,y,z,color1,color2,color3,alpha)
        myColor={color1,color2,color3,alpha}
        love.graphics.setColor(myColor)
        love.graphics.circle("fill",x,y,z) 
        love.graphics.setColor(1,1,1)
    end
    IsOk = 1;
    direction = "right";
    
end


function love.draw()
    --初始化界面
     love.graphics.draw(myBackground,0,0,0,0.3,0.3,0,0) 
     love.graphics.setColor(.20,.207,.208)
     local font=love.graphics.newFont("方正喵呜体.ttf",40)  
    love.graphics.setFont(font)
    love.graphics.print("夏目友人帐(^ ^)",225,25) 
    love.graphics.setColor(1,1,1)
    --设置边框
    love.graphics.setColor(.1,.4,.2)
    love.graphics.rectangle("line",365,95,360,310)
    love.graphics.rectangle("line",370,100,350,300)
    love.graphics.setColor(1,1,1)
    --设置小物体
    --love.graphics.setColor(.230, .137, .123)
    draw_ball(x,y,z,color1,color2,color3,alpha);
    --画按键
    Button_function:draw_button(0.2,0.2,0.4)
    Button_exist:draw_button(0.3,0.2,0.4)
    draw_page();
end

function love.update(dt)
    if Button_exist:isClick() and button_reset:isClick()then
        x = 378;
        y =108;
        IsOk = 1;
        color1 = 0.4;
        color2 = 0.4;
        color3 = 0.6;
        end
    if IsOk == 1 then
    if direction =='up' then
     x = x
     y = y - speed;
    elseif direction =='down' then
    x =x
    y = y + speed;
    elseif direction =='left' then
        x = x - speed;
        y = y ;
    elseif direction =='right' then
        x = x + speed;
        y = y;
    end
    color1 = color1+0.0005;
    color2 = color2+0.001;
    color3 = color3+0.001;
    if color1>1 or color2>1 or color3>1 then
        color1 = 0.4;
        color2 = 0.4;
        color3 = 0.6;
    end
end
if Button_function:isClick() and button_speed1:isClick()then
    speed = 1;
   end
   if Button_function:isClick() and button_speed2:isClick()then
    speed = 0.5;
   end
   if Button_function:isClick() and button_exit:isClick()then
       Button_function:reset()
       button_exit:reset()
   end
   if Button_exist:isClick() and button_exit1:isClick() then
      os.exit()
   end
   if Button_exist:isClick() and button_return:isClick()then
       Button_exist:reset()
       button_return:reset()
   end
    if x< 370+z or x > 720-z or y < 100 +z or y > 400 then
       IsOk = 0;
    end
end

function love.keypressed(keyboard)
    if keyboard == 'right' then
        direction = 'right'
    elseif keyboard == 'left' then
        direction = 'left'
    elseif keyboard == 'down' then
        direction = 'down'
    elseif keyboard == 'up' then
        direction = 'up'
    else
       IsOk = 0;
    end
end


